import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'amfe-flexible'
import './components/v-focus'
import ArticleItem from './components/ArticleItem.vue'
import {
  NavBar, Form,
  Field, Button,
  Tabbar, TabbarItem,
  Icon, Tab, Tabs,
  Cell, PullRefresh, List,
  ActionSheet, Dialog, Popup,
  Row, Col, Badge, Search, Divider,
  Tag, CellGroup, Image, DatetimePicker
} from 'vant'
import moment from 'moment'
Vue.component('ArticleItem', ArticleItem)
Vue.filter('Datefly', (ser) => {
  moment.locale('zh-cn')
  return moment(ser).from()
})
router.beforeEach((to, from, next) => {
  // 有token, 不能去登录页
  // 无token, 需要用户"权限"的才需要去登录页
  // store 是引入的 JS 文件
  if (store.state.token.length > 0 && to.path === '/login') {
    // 证明有token-已经登录了
    next(false) // 阻止跳转原地呆着
  } else {
    next()
  }
})
Vue.use(DatetimePicker)
Vue.use(Image)
Vue.use(Tag)
Vue.use(CellGroup)
Vue.use(NavBar)
Vue.use(Form)
Vue.use(Field)
Vue.use(Button)
Vue.use(Tabbar)
Vue.use(TabbarItem)
Vue.use(Icon)
Vue.use(Tab)
Vue.use(Tabs)
Vue.use(Cell)
Vue.use(PullRefresh)
Vue.use(List)
Vue.use(ActionSheet)
Vue.use(Dialog)
Vue.use(Popup)
Vue.use(Row)
Vue.use(Col)
Vue.use(Badge)
Vue.use(Search)
Vue.use(Divider)
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
